<template>
  <div>
    <el-card>
      <el-row>
        <span style="font-size: 23px;font-weight: bold">政策资源管理</span>
        <div class="custom-tabs ml20">
          <div class="custom-tab-btn"
               :class="{ active: state.tabs === 'unaudited' }"
               @click="page.handleClickTabs('unaudited')">
            待发布
          </div>
          <div class="custom-tab-btn"
               :class="{ active: state.tabs === 'audited' }"
               @click="page.handleClickTabs('audited')">
            已发布
          </div>
        </div>
      </el-row>
    </el-card>
    <div style="padding: 20px">
      <el-card>
        <el-row style="display: flex;align-items: center;padding: 15px 0px 15px 0px">
          <span>政策名称：</span>
          <el-input placeholder="请输入政策名称"
                    class="w-200"
                    v-model="state.where.title"/>
          <el-button class="btn ml10"
                     type="primary"
                     @click="page.load()">
            <el-icon>
              <elementSearch/>
            </el-icon>
            搜索
          </el-button>
          <el-button class="btn" @click="page.reset()">
            <el-icon>
              <elementRefreshRight/>
            </el-icon>
            重置
          </el-button>
          <el-button class="ml10"
                     type=""
                     @click="page.add()">
            <el-icon>
              <elementPlus/>
            </el-icon>
            新增
          </el-button>
        </el-row>
        <template v-if="state.tabs === 'unaudited'">
          <ld-table ref="tableRef"
                    url="/api/policy/policy/query/page"
                    :columns="columns"
                    :where="state.where"
                    :isTableTitle="false"
                    :isShowData="true"
                    :isPage="true">
            <template #action="scope">
              <el-link class="ml10"
                       size="small"
                       type="primary"
                       :underline="false"
                       @click=" page.openForm({id:scope.row.id})">
                编辑
              </el-link>
              <el-link class="ml10"
                       size="small"
                       type="primary"
                       :underline="false"
                       @click=" page.publicPolicy({id:scope.row.id})">
                发布
              </el-link>
              <el-link class="ml10"
                       size="small"
                       type="danger"
                       :underline="false"
                       @click=" page.delete(scope.row.id)">
                删除
              </el-link>
            </template>
          </ld-table>
        </template>
        <template v-if="state.tabs === 'audited'">
          <ld-table ref="tableRef"
                    url="/api/policy/policy/query/page"
                    :columns="columns"
                    :where="state.where"
                    :isTableTitle="false"
                    :isShowData="true"
                    :isPage="true">
            <template #action="scope">
              <el-link class="ml10"
                       size="small"
                       type="primary"
                       :underline="false"
                       @click=" page.openForm({id:scope.row.id})">
                取消发布
              </el-link>
            </template>
          </ld-table>
        </template>
      </el-card>
    </div>
  </div>
</template>
<script lang="ts" setup>
import {reactive, getCurrentInstance, ref, onMounted} from "vue";
import {useRouter, useRoute} from "vue-router";
import {approveMark} from "/@/views/enterpriseManager/dictionary/constant";

const returnDialogRef = ref<{ openDialog: () => void }>();
const {proxy} = getCurrentInstance() as any;
const router = useRouter();
const route = useRoute();
const tableRef = ref();

const state = reactive({
  tabs: "unaudited",
  tabShow: {
    unaudited: true,
    audited: false
  },
  where: {
    title: "",
    public: "",
    orderColumn: "create_time",
    orderFormat: "desc"
  },
});
const columns = [
  {
    prop: "title",
    label: "政策标题",
    minWidth: 220,
    align: "left",
  },
  {
    prop: "source",
    label: "数据来源",
    width: 150,
    align: "left",
  },
  {
    prop: "crtime",
    label: "创建时间",
    width: 120,
    align: "center",
  },
  {
    prop: "docpubtime",
    label: "发布时间",
    width: 120,
    align: "center",
  },
  {
    prop: "action",
    slot: "action",
    label: "操作",
    width: 300,
  }
]
const page = {
  add:() => {
    page.openForm();
  },
  reset: () => {
    state.where.title = "";
  },
  load: () => {
    tableRef.value.load();
  },
  delete: (keyValue: string) => {
    proxy.$wigem.confirm("是否删除？").then((res) => {
      // deleteEnterprise(keyValue).then((res) => {
      //   if (res.success) {
      //     proxy.$wigem.alert.success(res.msg);
      //     page.load()
      //   } else {
      //     proxy.$wigem.alert.error("保存失败");
      //   }
      // })
    });
  },
  publicPolicy: () => {

  },
  openForm: (params?: object) => {
    router.push({
      name: "policyForm",
      query: params
    })
  },
  handleClickTabs: (tabsName: string) => {
    state.tabs = tabsName;
    tabsName == "unaudited" ? state.where.public = "0" : state.where.public = "1";
  }
};

onMounted(() => {
});

</script>
<style lang="scss" scoped>

::v-deep(.el-card__body) {
  padding: 10px 20px 0 30px;
}

.custom-tabs {
  display: flex;
  gap: 10px;
  font-size: 20px;

  .custom-tab-btn {
    padding: 8px 16px;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
  }

  .custom-tab-btn.active {
    color: #409eff;
    border-bottom: 2px solid #409eff;
  }
}
</style>
